
package cj.web.activity.dao;
/*
 *  
 *  
*/
import java.util.List;

import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.SQL;
import net.paoding.rose.jade.annotation.SQLParam;
import cj.web.activity.domain.PrizeResult;
/**
 * 
 * @author 
 *
 */
@DAO
public interface PrizeResultDAO{
    
    @SQL("select * from PrizeResult where id=:1")
    PrizeResult queryById(String id);
    
    @SQL("select * from PrizeResult where DeviceID=:1 and ActiveID=:2")
    List<PrizeResult> queryByDeviceID(String DeviceID,String ActiveID);
    
    @SQL("select * from PrizeResult where ActiveID=:1 and Status<>:2")
    List<PrizeResult> queryByActiveID(int ActiveID,int Status);

    @SQL("select * from PrizeResult where ActiveID=:1 and Phone=:2")
    List<PrizeResult> queryByPhone(String ActiveID,String Phone);
    
    @SQL("INSERT INTO PrizeResult ("
			        		+ "ActiveID,"
			        		+ "Phone,"
			        		+ "DeviceID,"
			        		+ "DeviceType,"
			        		+ "CreateAT,"
			        		+ "Status,"
			        		+ "Remark"
							+") VALUES ("
							+ ":t.ActiveID,"
							+ ":t.Phone,"
							+ ":t.DeviceID,"
							+ ":t.DeviceType,"
							+ "now(),"
							+ ":t.Status,"
							+ ":t.Remark"
					+")")
    void create(@SQLParam("t") PrizeResult PrizeResult);
	
	@SQL("UPDATE PrizeResult SET "
		    		    						    			        + "ActiveID=:t.ActiveID,"
		        					    			        + "Phone=:t.Phone,"
		        					    			        + "DeviceID=:t.DeviceID,"
		        					    			        + "DeviceType=:t.DeviceType,"
		        					    			        + "CreateAT=:t.CreateAT,"
		        					    			        + "Status=:t.Status,"
		        					    			        + "Remark=:t.Remark"
		        						+ " WHERE ID=:t.ID")
    void update(@SQLParam("t") PrizeResult PrizeResult);
	
	// @SQL("SELECT  *    from   PrizeResult limit :1 ,:2  ")
	 
	 @SQL(" select ActiveID, Phone,DeviceID, date_format(CreateAT,'%Y-%m-%d %H:%i:%s') as CreateAT,Status,Remark "
	 		+ "from PrizeResult where ActiveID=:3  limit :1 ,:2 ")
	 List<PrizeResult> queryRSLimit(int begin ,int len,String aid);
	  
	 @SQL("SELECT  count(*)   from   PrizeResult  where ActiveID=:1")
	    int queryRSTotal(String aid);
	 
		@SQL("UPDATE PrizeResult SET  Status=:3  WHERE Phone=:2 and  DeviceID=:1 and ActiveID=:4"  )
         void updateState(String DeviceID ,String Phone,int Status,String aid);
		
		@SQL("UPDATE PrizeResult SET  Status=:2  WHERE ID=:1 "  )
        void updateStateByID(int id, int Status);
		
		@SQL("UPDATE active_gift_probability SET  count = count+1  WHERE name=:1 and  active_id=:2 "  )
        void updateCount(String name ,String active );
		


	    @SQL(" select ActiveID, Phone,DeviceID, date_format(CreateAT,'%Y-%m-%d %H:%i:%s') as CreateAT,Status,Remark "
	    		+ "from PrizeResult where ActiveID=:4 "
	    		+ "and (DeviceID  like " + "'%##(:3)%' or Phone  like " + "'%##(:3)%') limit :1 ,:2")
	    List<PrizeResult> queryBypd(int begin ,int len,String temp,String aid);
	    
	    
		 @SQL("SELECT  count(*)   from   PrizeResult  "
					+ " where DeviceID  like " + "'%##(:1)%'" 
	                +" or Phone like " + "'%##(:1)%'" 
					+" and ActiveID=:2") 
		    int queryRSTotalBypd(String temp,String aid);
	    
	    
//	    @SQL("SELECT paper_member.username as uname ,paper_member.nickname as nname ,FROM_UNIXTIME(regdate, '%Y-%m-%d') as udate     "
//	    		+ "FROM paper_member    ,paper_member_detail     where  paper_member.userid = paper_member_detail.userid "
//	    		+ "and (  paper_member.username like "+   "'%"+ "##(:4)"+  "%'" 
//	    		+ " or    paper_member.nickname like " +   "'%"+ "##(:4)"+  "%')"   
//	    		+ "  and regnum=:1     limit :2 ,:3  ")
//	    List<PrizeResult> queryRD_Limit( String regunm,int begin ,int len , String name);
	    
	    
	

}